package cn.swh.guguanjia.controller;

import cn.swh.guguanjia.entity.Result;
import cn.swh.guguanjia.entity.SysResource;
import cn.swh.guguanjia.service.SysResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mapper/resource")
public class SysResourceController {

    @Autowired
    SysResourceService service;


    @RequestMapping("selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize")
            int pageSize, @RequestParam Map<String, Object> map) {
        return new Result(service.selectPage(pageNum, pageSize, map));
    }

    @RequestMapping("toUpdate")
    public ModelAndView toUpdate() {
        return new ModelAndView("/menu/menu-save.html");
    }

    @RequestMapping(value = "doUpdate",method = RequestMethod.POST)
    public Result doUpdate(@RequestBody SysResource sysResource) {
        return new Result(service.updateByPrimaryKeySelective(sysResource));
    }

    @RequestMapping("toModules")
    public ModelAndView toModules(){
        return new ModelAndView("/modules/font-awesome.html");
    }

    @RequestMapping("selectAll")
    public Result selectAll() {
        SysResource sysResource = new SysResource();
        sysResource.setDelFlag("0");
        List<SysResource> sysAreas = service.select(sysResource);
        return new Result(sysAreas);
    }

    @RequestMapping("select")
    public Result select() {
        SysResource SysResource = new SysResource();
        SysResource.setDelFlag("0");
        return new Result(true, "查询成功", service.select(SysResource));
    }


    @RequestMapping("selectById")
    public Result selectById(long rid) {
        return new Result(true, "查询成功", service.selectById(rid));
    }


}
